import { SpriteFrame } from "cc"
import { HeroConfig } from "../settings/const"
import ResManager from "../common/ResManager"

export const NumberStrList = ['零', '一','二','三','四','五','六','七','八','九','十',]
export const LocationStrList:string[] = ['','前排左','前排中','前排右','中排左','中排中','中排右','后排左','后排中','后排右',]

export class Stone{
    heroId:number
    heroName: string
    name:string
    count:number
}

export class Hero {
    id: number 
    name: string 
    profession: number 
    enhance: string 
    effect: string 
    action1: string 
    action2: string 
    action3: string 
    action4: string 
    nature: number 
    locStr: number 
    boot: number
    star:number

    /**攻击 */
    Attack:number
    /**防御 */
    Defense:number
    /**当前进阶等级 */
    ad:number
    bp: {
        Compassion:number,
        Hamility:number,
        Honesty:number,
        Honor:number,
        Justice:number,
        Sacrifice:number,
        Spirituality:number,
        Valor:number
    }
    /**强化需要的碎片数量 */
    c_en:number
    /**升级需要的碎片数量 */
    c_up:number
    /**当前强化等级 */
    en:number
    /**当前等级 */
    l:number
    /**站位 */
    loc:number
    /**当前拥有强化魂石数量 */
    p:number

    static create(json:any):Hero{
        let hero = new Hero()
        for(let k in json){
            hero[k] = json[k]
        }

        return hero
    }

    static getListInHeroYard(items): Hero[]{
        let heroList:Hero[] = []
        for(let key in items){
            let id = key
            let value = items[key]

            let json = {
                ...HeroConfig[id],
                ...value
            }
            let hero = Hero.create(json)
           
            heroList.push(hero)
        }

        return heroList
    }

    /**
     * 获取头像
     * @returns 
     */
    async getHeadImg():Promise<SpriteFrame>{
        
        let sf = await ResManager.instance.loadAssetByUrl<SpriteFrame>(`heroHead/${this.id}/spriteFrame`)
      
        return sf
    }

    /**
     * 获取完整的图片
     * @returns 
     */
    async getImage():Promise<SpriteFrame>{
        let sf = await ResManager.instance.loadAssetByUrl<SpriteFrame>(`heroImage/${this.id}/spriteFrame`)
      
        return sf
    }

    /**
     * 最终攻击
     */
    get finalAttack():number{
        let num = this.Attack*(1+(0.045 + 0.005 * this.ad)*this.l);  //攻击，随等级上升, 步进值受品阶影响
        return Math.floor(num) 
    }

    /**
     * 最终防御
     */
    get finalDefense():number{
        let num = this.Defense*(1+(0.045 + 0.005 * this.ad)* this.l); //生命，随等级上升, 步进值受品阶影响
        return Math.floor(num) 
    }
    /**最大等级 */
    get maxLevel():number{

        return this.en * 10
    }
    /**最大星级 */
    get maxStar():number{
        return this.star + 3
    }
}